package com.kingyun.gpsinspection.purificationservice.services.tdm.outerservice.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.common.enums.ProblemTypeEnum;
import com.kingyun.gpsinspection.purificationservice.common.enums.TaskStatusEnum;
import com.kingyun.gpsinspection.purificationservice.common.enums.TaskTypeEnum;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.tdm.*;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.EmployeeVo;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.RedisValue;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.*;
import com.kingyun.gpsinspection.purificationservice.facade.service.tdm.IBMBPMService;
import com.kingyun.gpsinspection.purificationservice.facade.service.tdm.OutTaskInfoToJSONService;
import com.kingyun.gpsinspection.purificationservice.services.activitiservice.ext.util.ActivitiMakeDataUtil;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.TaskQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 任务统计信息对外接口，JSON格式。
 * Created by jiangjx on 2017/3/30.
 */
public class OutTaskInfoToJSONServiceImpl implements OutTaskInfoToJSONService {
    // BPM
    @Autowired
    public IBMBPMService ibmbpmService;

    @Autowired
    private TaskMapper taskMapper;

    @Autowired
    private TdmProblemMapper tdmProblemMapper;

    @Autowired
    private StatisticalManageTasksMapper statisticalManageTasksMapper;

    @Autowired
    private MaintenanceMapper maintenanceMapper;

    @Autowired
    private TdmWorkOrderMapper tdmWorkOrderMapper;

    @Autowired
    private MessageImpartMapper messageImpartMapper;

    @Autowired
    private WorkPermitMapper workPermitMapper;
    @Autowired
    protected TaskService taskservice;

    /**
     * 作业许可申请数(未超期)
     *
     * @param orgId 组织id
     */
    public JSONObject queryOperationLicenseCount(String orgId) {
        JSONObject jsonObject = new JSONObject();
        if (null != orgId) {
            Integer reInt = workPermitMapper.queryOperationLicenseCount(orgId);//根据组织id查询问题总数
            jsonObject.put("operationLicenseCount", reInt);
            return jsonObject;
        } else {
            jsonObject.put("operationLicenseCount", 0);
            return jsonObject;
        }
    }

    /**
     * 作业许可A类申请数(未超期)
     *
     * @param orgId 组织id
     */
    public JSONObject queryAOperationLicenseCount(String orgId) {
        JSONObject jsonObject = new JSONObject();
        if (null != orgId) {
            Integer reInt = workPermitMapper.queryAOperationLicenseCount(orgId);//根据组织id查询问题总数
            jsonObject.put("AoperationLicenseCount", reInt);
            return jsonObject;
        } else {
            jsonObject.put("AoperationLicenseCount", 0);
            return jsonObject;
        }
    }

    /**
     * 超期工单总数
     *
     * @param orgId 组织id
     */
    @Override
    public JSONObject queryOverdueWorkOrderCount(String orgId) {
        JSONObject jsonObject = new JSONObject();
        if (null != orgId) {
            Integer reInt = tdmWorkOrderMapper.queryOverdueWorkOrderCount(orgId);//根据人员id查询问题总数
            jsonObject.put("soonOverdueJob", reInt);
            return jsonObject;
        } else {
            jsonObject.put("soonOverdueJob", 0);
            return jsonObject;
        }
    }

    /**
     * 根据组织id查询问题总数
     *
     * @param orgId 组织id
     * @return jsonObject
     */
    @Override
    public JSONObject queryProblemCount(String orgId) {
        JSONObject jsonObject = new JSONObject();
        if (null != orgId) {
            Integer reInt = tdmProblemMapper.queryProblemCountByOrgId(orgId);//根据组织id查询问题总数
            jsonObject.put("problemCount", reInt);
            return jsonObject;
        } else {
            jsonObject.put("problemCount", 0);
            return jsonObject;
        }
    }

    /**
     * 查询我的待办数据
     *
     * @param redisValue 登录信息
     */
    @Override
    public JSONArray queryMyTodoInfo(RedisValue redisValue) {
        JSONArray array = new JSONArray();
        MessageImpartVo messageImpartVo = new MessageImpartVo();
        messageImpartVo.setUserId(redisValue.getUserId());
        messageImpartVo.setMessageSource((short) 1);
        //获取人员信息
        EmployeeVo employeeVo = redisValue.getEmployeeVo();
        //查询5条我的代办数据


        List<JSONObject> result = queryTodoInfo(employeeVo.getEmployeeId());
        //格式化待办信息
        array = formatToDoTask(result, array);
        array = orderByRemindTime(array);
        return array;
    }

    private List<JSONObject> queryTodoInfo(String employeeId) {
        TaskQuery taskQuery = taskservice.createTaskQuery().taskCandidateOrAssigned(employeeId).active().orderByTaskCreateTime().desc();
        //用户签收或者是没签收的任务
        List<org.activiti.engine.task.Task> assigneeTasks = taskQuery.listPage(0, 5);
        return ActivitiMakeDataUtil.makeTodoTaskPageData(assigneeTasks);
    }

    /**
     * 格式化待办信息
     *
     * @param result 代办源数据
     * @param array  返回数据
     */
    private JSONArray formatToDoTask(List<JSONObject> result, JSONArray array) {
        for (JSONObject jsonObject : result) {
            JSONObject obj = new JSONObject();
            //图标
            obj.put("icon", "notification-message-small");
            //set任务类型
            obj.put("myTodoItemName", jsonObject.get("taskType"));
            //set任务内容
            obj.put("myTodoItemContent", formatContent(jsonObject));
            //set提醒时间
            obj.put("remindTime", jsonObject.get("createTime"));
            //setURL
            obj.put("url", formatUrl(jsonObject));
            array.add(obj);
        }
        return array;
    }

    /**
     * 根据时间排序，并格式化日期显示为XX前
     *
     * @param array 源数据（待办+消息）
     */
    private JSONArray orderByRemindTime(JSONArray array) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        JSONArray array1 = new JSONArray();
        for (Object object : array) {
            JSONObject jsonObject = JSONObject.parseObject(object.toString());
            if (null == jsonObject.get("remindTime") && jsonObject.get("remindTime") == "") {
                jsonObject.put("remindTime", "-");
            } else {
                String date = null;
                try {
                    date = formatDate(dateFormat.parse(jsonObject.get("remindTime").toString()).getTime());
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                jsonObject.put("remindTime", date);
            }
            array1.add(jsonObject);
        }
        return array1;
    }

    /**
     * 取最新的5条消息格式化成首页要求的格式
     *
     * @param baseRows 消息源数据
     * @param array    待办已格式化后的数据
     */
    private JSONArray formatMessage(List<MessageImpartVo> baseRows, JSONArray array) {
        int size = baseRows.size() > 5 ? 5 : baseRows.size();
        for (int i = 0; i < size; i++) {
            MessageImpartVo messageImpartVo = baseRows.get(i);
            JSONObject obj = new JSONObject();
            //图标
            obj.put("icon", "notification-message-small");
            //set任务类型
            obj.put("myTodoItemName", "消息");
            //set任务内容
            obj.put("myTodoItemContent", messageImpartVo.getMessageContent());
            //set提醒时间
            obj.put("remindTime", messageImpartVo.getMessageTime());
            //setURL
            obj.put("url", formatMessagerUrl());
            array.add(obj);
        }
        return array;
    }

    /**
     * 格式化消息跳转url
     */
    private String formatMessagerUrl() {
        return "system/homepage/sitemesh/skip.htm?url=system/tdm/disposeMeasure/sitemesh/toList.htm";
    }

    /**
     * 格式化代办任务内容
     *
     * @param obj BPM对象
     */
    private Object formatContent(JSONObject obj) {
        return obj.get("startUser") + "于" + obj.get("createTime") + "创建的" + obj.get("taskType") + "任务,待您审核";
    }

    /**
     * 根据流程实例ID和任务类型名称查询任务发起相关信息
     *
     * @param PI_PIID
     * @return
     */
    public Task getTaskInfo(String PI_PIID) {
        if (StringUtils.isBlank(PI_PIID)) {
            return null;
        }
        Task task = taskMapper.findTaskByFlowId(PI_PIID);
        return task;
    }

    /**
     * 格式化URL
     *
     * @param jsonObject
     */
    private String formatUrl(JSONObject jsonObject) {
        if (jsonObject.get("taskType").equals("请假申请")) {
            return "system/iam/leave/sitemesh/to_todo_list.htm";
        } else if (jsonObject.get("taskType").equals("车辆申请")) {
            return "system/iam/AutoApply/sitemesh/switchPage.htm";
        } else if (jsonObject.get("taskType").equals("车辆调派")) {
            return "system/iam/carTransfer/sitemesh/toCarTransferTodoList.htm";
        } else if (jsonObject.get("taskType").equals("干部值班")) {
            return "system/dutyRecords/sitemesh/toListPage.htm";
        }
        return "system/tdm/task/sitemesh/toToDoList.htm";
    }

    /**
     * 格式化我的代办提醒时间
     *
     * @param messageTime
     */
    private String formatDate(long messageTime) {
        //获取当前时间
        Calendar calendar = Calendar.getInstance();
        //定义常量
        long ONE_MINUTE = 60000L;
        long ONE_HOUR = 3600000L;
        long ONE_DAY = 86400000L;
        long ONE_WEEK = 604800000L;
        String ONE_SECOND_AGO = "秒前";
        String ONE_MINUTE_AGO = "分钟前";
        String ONE_HOUR_AGO = "小时前";
        String ONE_DAY_AGO = "天前";
        String ONE_MONTH_AGO = "月前";
        String ONE_YEAR_AGO = "年前";

        //比较时间
        long millisecond = calendar.getTimeInMillis() - messageTime;
        if (millisecond < 1 * ONE_MINUTE) {
            long seconds = millisecond / 1000;
            return (seconds <= 0 ? 1 : seconds) + ONE_SECOND_AGO;
        }
        if (millisecond < 45L * ONE_MINUTE) {
            long minutes = millisecond / 1000 / 60;
            return (minutes <= 0 ? 1 : minutes) + ONE_MINUTE_AGO;
        }
        if (millisecond < 24L * ONE_HOUR) {
            long hours = millisecond / 1000 / 60 / 60;
            return (hours <= 0 ? 1 : hours) + ONE_HOUR_AGO;
        }
        if (millisecond < 48L * ONE_HOUR) {
            return "昨天";
        }
        if (millisecond < 30L * ONE_DAY) {
            long days = millisecond / 1000 / 60 / 60 / 24;
            return (days <= 0 ? 1 : days) + ONE_DAY_AGO;
        }
        if (millisecond < 12L * 4L * ONE_WEEK) {
            long months = millisecond / 1000 / 60 / 60 / 24 / 30;
            return (months <= 0 ? 1 : months) + ONE_MONTH_AGO;
        } else {
            long years = millisecond / 1000 / 60 / 60 / 24 / 30 / 365;
            return (years <= 0 ? 1 : years) + ONE_YEAR_AGO;
        }
    }

    /**
     * 问题类型分布(根据问题类型)
     * 方法里的查询语句与数据封装都根据问题类型枚举类来动态拼装，杜绝了写死代码，如果以后问题类型增加只需修改枚举类即可。
     *
     * @param orgId 组织id
     */
    @Override
    public JSONArray queryProblemSituation(String orgId) {
        JSONArray jsonArray = new JSONArray();
        if (null != orgId) {
            ProblemVo problemVo = new ProblemVo();
            Integer[] pType = new Integer[ProblemTypeEnum.values().length];
            for (int i = 0; i < ProblemTypeEnum.values().length; i++) {
                pType[i] = ProblemTypeEnum.values()[i].getCode();
            }
            problemVo.setProblemTypes(pType);
            problemVo.setOrgId(orgId);
            //根据组织id查询问题总数
            List<Map> list = tdmProblemMapper.queryProblemSituation(problemVo);
            //初始化存值MAP
            Map<String, Integer> temp_map = new HashMap<>();
            for (ProblemTypeEnum problemTypeEnum : ProblemTypeEnum.values()) {
                temp_map.put(problemTypeEnum.getCode().toString(), 0);
            }
            //循环处理查询出来的值
            for (Map map : list) {
                for (Object key : map.keySet()) {
                    for (String tkey : temp_map.keySet()) {
                        if (tkey.equals(key.toString().substring(key.toString().length() - 1))) {
                            temp_map.put(tkey, temp_map.get(tkey) + Integer.parseInt(map.get(key).toString()));
                        }
                    }
                }
            }
            //将数据转换成首页需要的json
            for (String key : temp_map.keySet()) {
                for (ProblemTypeEnum problemTypeEnum : ProblemTypeEnum.values()) {
                    if (Integer.parseInt(key) == problemTypeEnum.getCode()) {
                        JSONObject object = new JSONObject();
                        object.put("name", problemTypeEnum.getDecription());
                        object.put("value", temp_map.get(key));
                        jsonArray.add(object);
                        break;
                    }
                }
            }
            return jsonArray;
        } else {
            return jsonArray;
        }
    }

    /**
     * 问题状态统计(是否处置)
     *
     * @param orgId 组织id
     */
    @Override
    public JSONArray queryProblemAnalysis(String orgId) {
        JSONArray jsonArray = new JSONArray();
        List<Map> list = tdmProblemMapper.queryProblemAnalysis(orgId);//根据组织id查询问题分析数据
        Integer temp1 = 0, temp2 = 0;
        //累加数据
        for (Map map : list) {
            temp1 += Integer.parseInt(map.get("P1").toString());
            temp2 += Integer.parseInt(map.get("P2").toString());
        }
        //封装成页面所需的JSON格式
        JSONObject object = new JSONObject();
        object.put("name", "已处置");
        object.put("value", temp1);
        jsonArray.add(object);
        JSONObject object1 = new JSONObject();
        object1.put("name", "待处置");
        object1.put("value", temp2);
        jsonArray.add(object1);
        return jsonArray;
    }

    /**
     * 任务分布与完成情况（按作业区权限统计）
     *
     * @param orgId 组织id
     */
    @Override
    public JSONObject queryTaskInfoToBar(String orgId) {
        JSONObject jsonObject = new JSONObject();
        SMTVo smtVo = new SMTVo();
        smtVo.setOrgId(orgId);
        //查询数据
        List<SMT> baseRows = statisticalManageTasksMapper.queryTableList(smtVo);
        //x轴名称
        String[] name = new String[baseRows.size()];
        //任务总数
        Integer[] taskSum = new Integer[baseRows.size()];
        //已完成总数
        Integer[] completed = new Integer[baseRows.size()];
        //未完成总数
        Integer[] unfinished = new Integer[baseRows.size()];
        for (int i = 0; i < baseRows.size(); i++) {
            //setX轴名称
            name[i] = baseRows.get(i).getOrgName();
            //set任务总数
            taskSum[i] = baseRows.get(i).getTaskSum();
            //已完成总数
            completed[i] = baseRows.get(i).getCompleted();
            //未完成总数
            unfinished[i] = baseRows.get(i).getTaskSum() - baseRows.get(i).getCompleted();
        }
        //封装Y轴数值数组
        JSONArray value = new JSONArray();
        JSONObject object = new JSONObject();
        object.put("name", "任务总和");
        object.put("data", taskSum);
        value.add(object);
        JSONObject object1 = new JSONObject();
        object1.put("name", "已完成任务");
        object1.put("data", completed);
        value.add(object1);
        JSONObject object2 = new JSONObject();
        object2.put("name", "未完成任务");
        object2.put("data", unfinished);
        value.add(object2);
        //put数据
        jsonObject.put("x", name);
        jsonObject.put("y", value);
        return jsonObject;
    }

    /**
     * 任务类型分布情况
     *
     * @param orgId 组织id
     */
    @Override
    public JSONArray queryTaskType(String orgId) {
        SMTVo smtVo = new SMTVo();
        smtVo.setOrgId(orgId);
        List<SMT> baseRows = statisticalManageTasksMapper.loadPieInfo(smtVo);//查询数据
        //循环统计子部门的10大任务的总数
        Map<String, Short> map = new HashMap<>();
        for (SMT smt : baseRows) {
            //统计巡回检查
            map.put(TaskTypeEnum.TASK_TYPE_ENUM_1.getDecription(), map.containsKey(TaskTypeEnum.TASK_TYPE_ENUM_1.getDecription()) ? (short) (map.get(TaskTypeEnum.TASK_TYPE_ENUM_1.getDecription()) + smt.getTask1()) : smt.getTask1());
            //统计常规操作
            map.put(TaskTypeEnum.TASK_TYPE_ENUM_2.getDecription(), map.containsKey(TaskTypeEnum.TASK_TYPE_ENUM_2.getDecription()) ? (short) (map.get(TaskTypeEnum.TASK_TYPE_ENUM_2.getDecription()) + smt.getTask2()) : smt.getTask2());
            //统计维护保养
            map.put(TaskTypeEnum.TASK_TYPE_ENUM_3.getDecription(), map.containsKey(TaskTypeEnum.TASK_TYPE_ENUM_3.getDecription()) ? (short) (map.get(TaskTypeEnum.TASK_TYPE_ENUM_3.getDecription()) + smt.getTask3()) : smt.getTask3());
            //统计日常任务
            map.put(TaskTypeEnum.TASK_TYPE_ENUM_11.getDecription(), map.containsKey(TaskTypeEnum.TASK_TYPE_ENUM_11.getDecription()) ? (short) (map.get(TaskTypeEnum.TASK_TYPE_ENUM_11.getDecription()) + smt.getTask11()) : smt.getTask11());
        }
        return formatJSONArray(map);
    }

    /**
     * 任务分布与完成情况（按中心站权限统计）
     *
     * @param orgId 组织id
     */
    @Override
    public JSONArray queryTaskInfoToPie(String orgId) {
        SMTVo smtVo = new SMTVo();
        smtVo.setOrgId(orgId);
        //查询数据
        List<SMT> baseRows = statisticalManageTasksMapper.queryTableList(smtVo);
        //循环统计已完成，总任务个数。
        Map<String, Integer> map = new HashMap<>();
        for (SMT smt : baseRows) {
            map.put("已完成任务", map.containsKey("已完成任务") ? map.get("已完成任务") + smt.getCompleted() : smt.getCompleted());
            map.put("未完成任务", map.containsKey("未完成任务") ? map.get("未完成任务") + (smt.getTaskSum() - smt.getCompleted()) : smt.getTaskSum() - smt.getCompleted());
        }
        return formatJSONArray(map);
    }

    /**
     * 当月维护保养情况（按维护保养任务的超期、即将超期、正常状态统计）
     *
     * @param orgId 组织id
     */
    @Override
    public JSONArray queryEquipmentMaintenance(String orgId) {
        //封装查询条件
        MaintenanceVo maintenanceVo = new MaintenanceVo();
        maintenanceVo.setOrgId(orgId);
        Calendar calendar = Calendar.getInstance();
        //取当月第一天
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        maintenanceVo.setPlanStartTime(calendar.getTime());
        //取当月最后一天
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DATE));
        maintenanceVo.setPlanEndTime(calendar.getTime());
        //查询当月的维护保养任务基本信息(不包含周期任务)
        List<MaintenanceVo> list = maintenanceMapper.queryMaintenanceToDate(maintenanceVo);
        Map map = statisticsInfo(list);
        return formatJSONArray(map);
    }

    /**
     * 统计正常，超期，即将超期数据
     *
     * @param list 基本数据
     */
    private Map statisticsInfo(List<MaintenanceVo> list) {
        Map map = new HashMap<>();
        //定义变量正常，超期，即将超期
        Integer normal = 0, overdue = 0, willExpire = 0;
        //获取当前系统时间
        Calendar calendar = Calendar.getInstance();
        //循环List统计数据
        for (MaintenanceVo maintenanceVo : list) {
            //获取总计划的毫秒数
            long temp_cycle1 = maintenanceVo.getPlanEndTime().getTime() - maintenanceVo.getPlanStartTime().getTime();
            //获取已使用时间的毫秒数
            long temp_cycle2 = calendar.getTimeInMillis() - maintenanceVo.getPlanStartTime().getTime();
            //条件一:所有已完成的均为正常
            if (new Integer(maintenanceVo.getTaskStatus().toString()) == TaskStatusEnum.TASK_STATUS_ENUM_3.code()) {
                normal++;
            } else {
                //条件二:未完成且使用的时间未超过75%为正常
                if (temp_cycle2 <= temp_cycle1 * 0.75) {
                    normal++;
                } else if (temp_cycle2 > temp_cycle1 * 0.75 && temp_cycle2 <= temp_cycle1) {
                    //条件三:未完成且使用的时间已经超过75%为即将超期
                    willExpire++;
                } else if (calendar.getTimeInMillis() > maintenanceVo.getPlanEndTime().getTime()) {
                    //条件四:未完成且使用的时间超过了计划结束时间为超期
                    overdue++;
                }
            }
        }

        //装载数据
        map.put("正常", normal);
        map.put("超期", overdue);
        map.put("即将超期", willExpire);
        return map;
    }

    /**
     * 格式化数据为JSONArray格式
     *
     * @param map 源数据
     */
    private JSONArray formatJSONArray(Map map) {
        JSONArray jsonArray = new JSONArray();
        //封装数据为首页需要的格式
        for (Object key : map.keySet()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("value", map.get(key));
            jsonObject.put("name", key);
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    public JSONArray queryIndexTopInfo(RedisValue redisValue) throws Exception {
        EmployeeVo employeeVo = redisValue.getEmployeeVo();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        SMT smt;
        //我的待办总数
        TaskQuery taskQuery = taskservice.createTaskQuery().taskCandidateOrAssigned(employeeVo.getEmployeeId()).active();
        jsonObject.put("id", 1);
        jsonObject.put("title", "我的待办");
        jsonObject.put("num", taskQuery.count());
        jsonObject.put("icon", "mail-icon");
        jsonArray.add(jsonObject);
        //我发起的任务占比
        smt = statisticalManageTasksMapper.queryMyTaskPercent(employeeVo.getEmployeeId());
        jsonArray.add(formatData(smt, "我发起的任务占比", 2));
        //我发起的问题占比
        smt = statisticalManageTasksMapper.queryProblemPercent(employeeVo.getEmployeeId());
        jsonArray.add(formatData(smt, "我发起的问题占比", 3));
        //我发起的请假占比
        smt = statisticalManageTasksMapper.queryLeavePercent(employeeVo.getEmployeeId());
        jsonArray.add(formatData(smt, "我发起的请假占比", 4));
        //我发起的出差占比
        smt = statisticalManageTasksMapper.queryBusinessPercent(employeeVo.getEmployeeId());
        jsonArray.add(formatData(smt, "我发起的出差占比", 5));
        //我发起的用车占比
        smt = statisticalManageTasksMapper.queryPickUpPercent(employeeVo.getEmployeeId());
        jsonArray.add(formatData(smt, "我发起的用车占比", 6));
        return jsonArray;
    }

    /**
     * 格式化顶部数据
     *
     * @param smt 查询的原始数据
     * @return
     */
    private Object formatData(SMT smt, String title, Integer id) {
        JSONObject jsonObject = new JSONObject();
        //获取格式化对象
        NumberFormat nt = NumberFormat.getPercentInstance();
        //设置百分数精确度2即保留两位小数
        nt.setMinimumFractionDigits(2);
        if (null == smt.getTask1() || smt.getTask1() == 0) {
            jsonObject.put("id", id);
            jsonObject.put("title", title);
            jsonObject.put("percent", nt.format(0));
        } else {
            if (null == smt.getTask2() || smt.getTask2().equals("")) {
                smt.setTask2((short) 0);
            }
            Double percent = Double.valueOf(smt.getTask2().toString()) / Double.valueOf(smt.getTask1().toString());
            jsonObject.put("id", id);
            jsonObject.put("title", title);
            jsonObject.put("percent", nt.format(percent));
        }
        return jsonObject;
    }
}
